using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Requests Data Object Class
  /// </summary>
  public partial class DORequests
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Requests RequestId
		/// </summary>
		public const string RowRequestId = "Request_ID";

		/// <summary>
		/// The Table Column for the Requests CreatedByUserId
		/// </summary>
		public const string RowCreatedByUserId = "CreatedByUser_ID";

		/// <summary>
		/// The Table Column for the Requests RequestDate
		/// </summary>
		public const string RowRequestDate = "RequestDate";

		/// <summary>
		/// The Table Column for the Requests RequestStatus
		/// </summary>
		public const string RowRequestStatus = "RequestStatus";

		/// <summary>
		/// The Table Column for the Requests Comments
		/// </summary>
		public const string RowComments = "Comments";

		/// <summary>
		/// The Table Column for the Requests ApprovedByUserId
		/// </summary>
		public const string RowApprovedByUserId = "ApprovedByUser_ID";

		/// <summary>
		/// The Table Column for the Requests ApprovedDate
		/// </summary>
		public const string RowApprovedDate = "ApprovedDate";

		/// <summary>
		/// The Table Column for the Requests OpenByUserId
		/// </summary>
		public const string RowOpenByUserId = "OpenByUser_ID";

		/// <summary>
		/// The Table Column for the Requests OpenDate
		/// </summary>
		public const string RowOpenDate = "OpenDate";

		/// <summary>
		/// The Table Column for the Requests ClosedByUserId
		/// </summary>
		public const string RowClosedByUserId = "ClosedByUser_ID";

		/// <summary>
		/// The Table Column for the Requests ClosedDate
		/// </summary>
		public const string RowClosedDate = "ClosedDate";

		/// <summary>
		/// The Table Column for the Requests DepartmentName
		/// </summary>
		public const string RowDepartmentName = "DepartmentName";

		/// <summary>
		/// The Table Column for the Requests DivisionName
		/// </summary>
		public const string RowDivisionName = "DivisionName";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spRequests_Create";
private const string m_StoredProcedureConstDelete = "spRequests_Delete";
private const string m_StoredProcedureConstRetrieve = "spRequests_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spRequests_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spRequests_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private int m_RequestId;
		private long m_CreatedByUserId;
		private DateTime m_RequestDate;
		private string m_RequestStatus;
		private string m_Comments;
		private long m_ApprovedByUserId;
		private DateTime m_ApprovedDate;
		private long m_OpenByUserId;
		private DateTime m_OpenDate;
		private long m_ClosedByUserId;
		private DateTime m_ClosedDate;
		private string m_DepartmentName;
		private string m_DivisionName;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DORequests> m_Requestss = new List<DORequests>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DORequests() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// RequestId
		/// </summary>
		/// <remarks>
		/// This property contains the Requests RequestId
		/// </remarks>
		public int RequestId
		{
			get { return (this.m_RequestId); }
			set { this.m_RequestId = value; }
		}

		/// <summary>
		/// CreatedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Requests CreatedByUserId
		/// </remarks>
		public long CreatedByUserId
		{
			get { return (this.m_CreatedByUserId); }
			set { this.m_CreatedByUserId = value; }
		}

		/// <summary>
		/// RequestDate
		/// </summary>
		/// <remarks>
		/// This property contains the Requests RequestDate
		/// </remarks>
		public DateTime RequestDate
		{
			get { return (this.m_RequestDate); }
			set { this.m_RequestDate = value; }
		}

		/// <summary>
		/// RequestStatus
		/// </summary>
		/// <remarks>
		/// This property contains the Requests RequestStatus
		/// </remarks>
		public string RequestStatus
		{
			get { return (this.m_RequestStatus); }
			set { this.m_RequestStatus = value; }
		}

		/// <summary>
		/// Comments
		/// </summary>
		/// <remarks>
		/// This property contains the Requests Comments
		/// </remarks>
		public string Comments
		{
			get { return (this.m_Comments); }
			set { this.m_Comments = value; }
		}

		/// <summary>
		/// ApprovedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Requests ApprovedByUserId
		/// </remarks>
		public long ApprovedByUserId
		{
			get { return (this.m_ApprovedByUserId); }
			set { this.m_ApprovedByUserId = value; }
		}

		/// <summary>
		/// ApprovedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Requests ApprovedDate
		/// </remarks>
		public DateTime ApprovedDate
		{
			get { return (this.m_ApprovedDate); }
			set { this.m_ApprovedDate = value; }
		}

		/// <summary>
		/// OpenByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Requests OpenByUserId
		/// </remarks>
		public long OpenByUserId
		{
			get { return (this.m_OpenByUserId); }
			set { this.m_OpenByUserId = value; }
		}

		/// <summary>
		/// OpenDate
		/// </summary>
		/// <remarks>
		/// This property contains the Requests OpenDate
		/// </remarks>
		public DateTime OpenDate
		{
			get { return (this.m_OpenDate); }
			set { this.m_OpenDate = value; }
		}

		/// <summary>
		/// ClosedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Requests ClosedByUserId
		/// </remarks>
		public long ClosedByUserId
		{
			get { return (this.m_ClosedByUserId); }
			set { this.m_ClosedByUserId = value; }
		}

		/// <summary>
		/// ClosedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Requests ClosedDate
		/// </remarks>
		public DateTime ClosedDate
		{
			get { return (this.m_ClosedDate); }
			set { this.m_ClosedDate = value; }
		}

		/// <summary>
		/// DepartmentName
		/// </summary>
		/// <remarks>
		/// This property contains the Requests DepartmentName
		/// </remarks>
		public string DepartmentName
		{
			get { return (this.m_DepartmentName); }
			set { this.m_DepartmentName = value; }
		}

		/// <summary>
		/// DivisionName
		/// </summary>
		/// <remarks>
		/// This property contains the Requests DivisionName
		/// </remarks>
		public string DivisionName
		{
			get { return (this.m_DivisionName); }
			set { this.m_DivisionName = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DORequests> Requestss
	{
	  get { return m_Requestss; }
	  set { m_Requestss = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowRequest_ID + "=" + this.Request_ID);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowRequestId].ToString() != "")
			this.RequestId = int.Parse(dr[RowRequestId].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			this.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowRequestDate].ToString() != "")
			this.RequestDate = DateTime.Parse(dr[RowRequestDate].ToString());

		if (dr[RowRequestStatus].ToString() != "")
			this.RequestStatus = dr[RowRequestStatus].ToString();

		if (dr[RowComments].ToString() != "")
			this.Comments = dr[RowComments].ToString();

		if (dr[RowApprovedByUserId].ToString() != "")
			this.ApprovedByUserId = long.Parse(dr[RowApprovedByUserId].ToString());

		if (dr[RowApprovedDate].ToString() != "")
			this.ApprovedDate = DateTime.Parse(dr[RowApprovedDate].ToString());

		if (dr[RowOpenByUserId].ToString() != "")
			this.OpenByUserId = long.Parse(dr[RowOpenByUserId].ToString());

		if (dr[RowOpenDate].ToString() != "")
			this.OpenDate = DateTime.Parse(dr[RowOpenDate].ToString());

		if (dr[RowClosedByUserId].ToString() != "")
			this.ClosedByUserId = long.Parse(dr[RowClosedByUserId].ToString());

		if (dr[RowClosedDate].ToString() != "")
			this.ClosedDate = DateTime.Parse(dr[RowClosedDate].ToString());

		if (dr[RowDepartmentName].ToString() != "")
			this.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowDivisionName].ToString() != "")
			this.DivisionName = dr[RowDivisionName].ToString();
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DORequests Requests = new DORequests();
			
					if (dr[RowRequestId].ToString() != "")
			Requests.RequestId = int.Parse(dr[RowRequestId].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			Requests.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowRequestDate].ToString() != "")
			Requests.RequestDate = DateTime.Parse(dr[RowRequestDate].ToString());

		if (dr[RowRequestStatus].ToString() != "")
			Requests.RequestStatus = dr[RowRequestStatus].ToString();

		if (dr[RowComments].ToString() != "")
			Requests.Comments = dr[RowComments].ToString();

		if (dr[RowApprovedByUserId].ToString() != "")
			Requests.ApprovedByUserId = long.Parse(dr[RowApprovedByUserId].ToString());

		if (dr[RowApprovedDate].ToString() != "")
			Requests.ApprovedDate = DateTime.Parse(dr[RowApprovedDate].ToString());

		if (dr[RowOpenByUserId].ToString() != "")
			Requests.OpenByUserId = long.Parse(dr[RowOpenByUserId].ToString());

		if (dr[RowOpenDate].ToString() != "")
			Requests.OpenDate = DateTime.Parse(dr[RowOpenDate].ToString());

		if (dr[RowClosedByUserId].ToString() != "")
			Requests.ClosedByUserId = long.Parse(dr[RowClosedByUserId].ToString());

		if (dr[RowClosedDate].ToString() != "")
			Requests.ClosedDate = DateTime.Parse(dr[RowClosedDate].ToString());

		if (dr[RowDepartmentName].ToString() != "")
			Requests.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowDivisionName].ToString() != "")
			Requests.DivisionName = dr[RowDivisionName].ToString();

            this.Requestss.Add(Requests);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
